home *** CD-ROM | disk | FTP | other *** search
/ Cre@te Online 2000 December / Cre@teOnline CD05.iso / MacSoft / XML ConsoleMax.sea / XML ConsoleMax / Required / esc.jar / com / extensibility / xml / URI.class (.txt) < prev    next >
Encoding:
Java Class File  |  2000-06-30  |  7.1 KB  |  276 lines

  1. package com.extensibility.xml;
  2.  
  3. import com.extensibility.plugin.PluginRegistry;
  4. import com.extensibility.plugin.api.URIScheme;
  5. import java.io.File;
  6. import java.io.IOException;
  7. import java.io.InputStream;
  8. import java.io.Reader;
  9. import java.io.Writer;
  10. import java.net.URL;
  11.  
  12. public class URI {
  13.    private URIScheme scheme;
  14.    private URI baseURI = null;
  15.    private String relPath = null;
  16.    private static int RO_UNDETERMINED = 0;
  17.    private static int IS_READ_ONLY = 1;
  18.    private static int IS_WRITEABLE = 2;
  19.    private int readOnlyState;
  20.    private static URISchemeRegistry registry = new URISchemeRegistry();
  21.    private static URIScheme virginScheme = new VirginURIScheme();
  22.    public static final String STRING_SCHEME = ":xa-string";
  23.    public static final String VIRGIN_SCHEME = ":xa-virgin";
  24.    public static final String FILE_SCHEME = "file";
  25.  
  26.    public static URISchemeRegistry getRegistry() {
  27.       return registry;
  28.    }
  29.  
  30.    public static void registerSchemes() {
  31.       PluginRegistry var0 = PluginRegistry.getRegistry();
  32.       int var1 = var0.getPluginApiCount("URIScheme10");
  33.  
  34.       for(int var2 = 0; var2 < var1; ++var2) {
  35.          Object var3 = var0.getNthPlugin("URIScheme10", var2);
  36.          URIScheme var4 = (URIScheme)var3;
  37.          if (var4 != null) {
  38.             var4.registerSchemes(registry);
  39.          }
  40.       }
  41.  
  42.    }
  43.  
  44.    public static void registerUsualSchemes() {
  45.       (new URIFileScheme()).registerSchemes(registry);
  46.       (new URIUrlScheme()).registerSchemes(registry);
  47.       (new URIStringScheme()).registerSchemes(registry);
  48.    }
  49.  
  50.    public static URI makeStringURI(String var0) {
  51.       URIScheme var1 = registry.makeURIScheme(Class.forName("java.lang.String"), var0);
  52.       return new URI(var1);
  53.    }
  54.  
  55.    public URI() {
  56.       this.readOnlyState = RO_UNDETERMINED;
  57.       this.scheme = virginScheme;
  58.    }
  59.  
  60.    public URI(File var1) {
  61.       this.readOnlyState = RO_UNDETERMINED;
  62.       this.scheme = registry.makeURIScheme(Class.forName("java.io.File"), var1);
  63.       this.relPath = this.scheme.getFullPath();
  64.    }
  65.  
  66.    public URI(URIScheme var1) {
  67.       this.readOnlyState = RO_UNDETERMINED;
  68.       this.scheme = var1;
  69.       this.relPath = var1.getFullPath();
  70.    }
  71.  
  72.    public URI(URL var1) {
  73.       this.readOnlyState = RO_UNDETERMINED;
  74.       this.scheme = registry.makeURIScheme(Class.forName("java.net.URL"), var1);
  75.       this.relPath = this.scheme.getFullPath();
  76.    }
  77.  
  78.    public URI(String var1) {
  79.       this.readOnlyState = RO_UNDETERMINED;
  80.       this.buildURI(var1);
  81.    }
  82.  
  83.    private String extractScheme(String var1, boolean var2) {
  84.       String var3 = null;
  85.       int var4 = var1.indexOf(58);
  86.       if (var4 >= 0) {
  87.          var3 = var1.substring(0, var4);
  88.          if (var2 && !registry.isValidSchemeName(var3)) {
  89.             var3 = null;
  90.          }
  91.       }
  92.  
  93.       return var3;
  94.    }
  95.  
  96.    private void buildURI(String var1) {
  97.       this.relPath = var1;
  98.       String var2 = this.extractScheme(var1, false);
  99.       if (var2 != null) {
  100.          this.scheme = registry.makeURIScheme(var2, var1);
  101.       }
  102.  
  103.       if (this.scheme == null) {
  104.          if (var1.length() > 0) {
  105.             this.scheme = registry.makeURIScheme(Class.forName("java.io.File"), new File(var1));
  106.          } else {
  107.             this.scheme = virginScheme;
  108.          }
  109.       }
  110.  
  111.    }
  112.  
  113.    public URI(URI var1, String var2) {
  114.       for(this.readOnlyState = RO_UNDETERMINED; var1 != null && !var1.hasPersistence(); var1 = var1.getBaseURI()) {
  115.       }
  116.  
  117.       boolean var3 = var2.startsWith("x-schema:");
  118.       if (var3) {
  119.          var2 = var2.substring(9);
  120.       }
  121.  
  122.       if (var1 != null && this.extractScheme(var2, true) == null) {
  123.          this.relPath = var2;
  124.          this.scheme = var1.scheme.construct(var2);
  125.          this.baseURI = var1;
  126.       } else {
  127.          this.buildURI(var2);
  128.       }
  129.  
  130.    }
  131.  
  132.    private URI(URI var1, URIScheme var2) {
  133.       this.readOnlyState = RO_UNDETERMINED;
  134.       this.scheme = var2;
  135.       this.baseURI = var1;
  136.    }
  137.  
  138.    public URIScheme getSchemeObject() {
  139.       return this.scheme;
  140.    }
  141.  
  142.    public URI getParent() {
  143.       URIScheme var1 = this.scheme.toParent();
  144.       return var1 != null ? new URI(var1) : null;
  145.    }
  146.  
  147.    public String getRelativeName(URI var1) {
  148.       String var2;
  149.       if (this.scheme.getScheme().equals(var1.scheme.getScheme())) {
  150.          var2 = this.scheme.computeRelative(var1.scheme);
  151.          if (var2 == null) {
  152.             var2 = this.scheme.getFullPath();
  153.          }
  154.       } else {
  155.          var2 = this.scheme.getFullPath();
  156.       }
  157.  
  158.       return var2;
  159.    }
  160.  
  161.    public URI makeRelative(URI var1) {
  162.       URI var2 = this;
  163.       if (var1 != null) {
  164.          if (this.scheme.hasPersistence()) {
  165.             if (var1.scheme.getScheme().equals(this.scheme.getScheme())) {
  166.                String var3 = this.scheme.computeRelative(var1.scheme);
  167.                if (var3 != null) {
  168.                   var2 = new URI(var1, var3);
  169.                }
  170.             }
  171.          } else {
  172.             var2 = new URI(var1, this.scheme);
  173.          }
  174.       }
  175.  
  176.       return var2;
  177.    }
  178.  
  179.    public URI getBaseURI() {
  180.       return this.baseURI;
  181.    }
  182.  
  183.    public String getScheme() {
  184.       return this.scheme.getScheme();
  185.    }
  186.  
  187.    public long getLength() {
  188.       return this.scheme.getLength();
  189.    }
  190.  
  191.    public URI renameTo(String var1) {
  192.       return new URI(this.scheme.renameTo(var1));
  193.    }
  194.  
  195.    public InputStream createInputStream() throws IOException {
  196.       return this.scheme.createInputStream();
  197.    }
  198.  
  199.    public Reader createReader() throws IOException {
  200.       return this.scheme.createReader();
  201.    }
  202.  
  203.    public XMLReader createXMLReader() throws IOException {
  204.       return new XMLReader(this.scheme.createInputStream());
  205.    }
  206.  
  207.    public Writer createWriter(int var1) throws IOException {
  208.       return new XMLWriter(this.scheme.createOutputStream(), var1);
  209.    }
  210.  
  211.    public Writer createWriter() throws IOException {
  212.       return this.scheme.createWriter();
  213.    }
  214.  
  215.    public boolean hasPersistence() {
  216.       return this.scheme.hasPersistence();
  217.    }
  218.  
  219.    public boolean isEmpty() {
  220.       return this.scheme.isEmpty();
  221.    }
  222.  
  223.    public boolean equals(URI var1) {
  224.       return var1 != null && this.scheme.getScheme().equals(var1.scheme.getScheme()) && this.scheme.equals(var1.scheme);
  225.    }
  226.  
  227.    public int compareTo(URI var1) {
  228.       int var2 = this.scheme.getScheme().compareTo(var1.scheme.getScheme());
  229.       if (var2 == 0) {
  230.          var2 = this.scheme.compareTo(var1.scheme);
  231.       }
  232.  
  233.       return var2;
  234.    }
  235.  
  236.    public boolean exists() {
  237.       return this.scheme.exists();
  238.    }
  239.  
  240.    public boolean isReadOnly() {
  241.       return this.isReadOnly(false);
  242.    }
  243.  
  244.    public boolean isReadOnly(boolean var1) {
  245.       if (this.readOnlyState == RO_UNDETERMINED || var1) {
  246.          this.readOnlyState = this.scheme.isReadOnly() ? IS_READ_ONLY : IS_WRITEABLE;
  247.       }
  248.  
  249.       return this.readOnlyState == IS_READ_ONLY;
  250.    }
  251.  
  252.    public int hashCode() {
  253.       return this.getShortName().hashCode() ^ 1234321;
  254.    }
  255.  
  256.    public String getShortName() {
  257.       return this.scheme.getShortName();
  258.    }
  259.  
  260.    public String getFullName() {
  261.       return this.scheme.getFullPath();
  262.    }
  263.  
  264.    public String getUIName() {
  265.       return this.scheme.getUIName();
  266.    }
  267.  
  268.    public String toSource() {
  269.       return this.relPath;
  270.    }
  271.  
  272.    public Object getInterface(Class var1) {
  273.       return this.scheme.getInterface(var1);
  274.    }
  275. }
  276.